package com.ktg.web.mainData;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ktg.ktgcommon.domain.mainData.MdVendor;
import com.ktg.ktgcommon.domain.mainData.MdWorkshop;
import com.ktg.ktgcommon.query.QueryVendor;
import com.ktg.ktgcommon.result.R;
import com.ktg.service.WorkshopService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class WorkshopController {

    @Autowired
    private WorkshopService workshopService;

    @PostMapping("/workshop/checkListWorkshop")
    public R checkListWorkshop(String workshopCode, String workshopName,
                               @RequestParam(defaultValue = "1") Integer pageNo,
                               @RequestParam(defaultValue = "5") Integer pageSize) {

        Page<MdWorkshop> page = new Page<>(pageNo, pageSize);

        Page<MdWorkshop> selectPage = workshopService.selectPage(page, workshopCode, workshopName);
        return R.OK(selectPage);
    }

    @PostMapping("/workshop/checkWorkshopById/{workshopId}")
    public R checkWorkshopById(@PathVariable Long workshopId) {
        MdWorkshop mdWorkshop = workshopService.checkWorkshopById(workshopId);
        return R.OK(mdWorkshop);
    }

    @PostMapping("/workshop/AddOrChWorkshop")
    public R AddOrChWorkshop(MdWorkshop mdWorkshop) {
        Integer integer = workshopService.AddOrChWorkshop(mdWorkshop);
        return R.OK(integer);
    }
    @DeleteMapping("/workshop/delWorkshop/{workshopId}")
    public R delWorkshop(@PathVariable Long workshopId) {
        Integer integer = workshopService.delWorkshop(workshopId);
        return R.OK(integer);
    }

    @DeleteMapping("/workshop/delWorkshopIdArray")
    public R delClientIdArray(@RequestBody List<Long> arrayWorkshopId){
        System.out.println(arrayWorkshopId);
        Integer integer = workshopService.delClientIdArray(arrayWorkshopId);
        return R.OK(integer);
    }
    @PostMapping("/workshop/workshopCheckAll")
    public R workshopCheckAll(){
        List<MdWorkshop> list = workshopService.checkAll();
        return R.OK(list);
    }
}
